<template>
  <el-row :gutter="16" v-if="data && !loading">
    <el-col :span="5">
      <div class="statistic-card">
        <el-statistic :value="data['person_infom'].toLocaleString()">
          <template #title>
            <div style="display: inline-flex; align-items: center">
              总用户数
              <el-tooltip effect="dark" placement="top">
                <el-icon style="margin-left: 4px" :size="12">
                  <Warning />
                </el-icon>
              </el-tooltip>
            </div>
          </template>
          <!-- <template #suffix> {{ (data['person_infom']).toLocaleString() }}</template> -->
        </el-statistic>
        <!-- <div class="statistic-footer">
          <div class="footer-item">
            <span>占比</span>
            <span class="green">
              24%
              <el-icon>
                <CaretTop />
              </el-icon>
            </span>
          </div>
        </div> -->
      </div>
    </el-col>
    <el-col :span="5">
      <div class="statistic-card">
        <el-statistic :value="merchantCount.toLocaleString()">
          <template #title>
            <div style="display: inline-flex; align-items: center">
              总商户数
              <el-tooltip effect="dark" placement="top">
                <el-icon style="margin-left: 4px" :size="12">
                  <Warning />
                </el-icon>
              </el-tooltip>
            </div>
          </template>
          <!-- <template #suffix> / 34,000,000</template> -->
        </el-statistic>
        <!-- <div class="statistic-footer">
          <div class="footer-item">
            <span>占比</span>
            <span class="red">
              12%
              <el-icon>
                <CaretBottom />
              </el-icon>
            </span>
          </div>
        </div> -->
      </div>
    </el-col>

    <el-col :span="4">
      <dv-border-box-8>
        <div style="text-align: center; padding: 10px;">
          <div style="font-size: 18px; color: white;">画像总数</div>
          <div style="font-size: 28px; color: white; font-family: 'LCD', sans-serif;">{{
            // portraitCount.toLocaleString()
            Math.min(gPortraitCount, data['person_infom'] + merchantCount).toLocaleString()
          }}
          </div>
        </div>
      </dv-border-box-8>
    </el-col>
    <el-col :span="5">
      <div class="statistic-card">
        <el-statistic :value="data['person_card']?.toLocaleString()" title="New transactions today">
          <template #title>
            <div style="display: inline-flex; align-items: center">
              总卡数
            </div>
          </template>
          <!-- <template #suffix> / 3,004,000,000</template> -->
        </el-statistic>
        <!-- <div class="statistic-footer">
          <div class="footer-item">
            <span>占比</span>
            <span class="green">
              16%
              <el-icon>
                <CaretTop />
              </el-icon>
            </span>
          </div>
          <div class="footer-item">
            <el-icon :size="14">
              <ArrowRight />
            </el-icon>
          </div>
        </div> -->
      </div>
    </el-col>
    <el-col :span="5">
      <div class="statistic-card">
        <el-statistic :value="labelCount" title="New transactions today">
          <template #title>
            <div style="display: inline-flex; align-items: center">
              智能标签数 / 总标签数
            </div>
          </template>
          <template #prefix> 66 /</template>
        </el-statistic>
      </div>
    </el-col>
  </el-row>
</template>

<script lang="ts" setup>
import { useMetaStore } from '@/stores/meta'
import { nebulaExec } from '@/utils/request'
import {
  ArrowRight,
  CaretBottom,
  CaretTop,
  Warning,
} from '@element-plus/icons-vue'
import { sum } from 'lodash'
import { ref } from 'vue'

const props = defineProps(['data'])

const loading = ref(true)
const scenarioStat = ref({})
const labelCount = ref(0)
const merchantCount = ref(window.MERCHANT_COUNT)
const portraitCount = ref(window.PORTRAIT_COUNT)
const gPortraitCount = ref(window.PORTRAIT_COUNT)

const scenarios = {
  'abnorm_hn_mchnt': '黄牛营销',
  'gambling_card': '赌博违规',
  'abnorm_trans_card': '异常转账',
  'card_weimao_label': '伪冒注册',
  'mchnt_label': '商户违规',
  'mcht_taoxian_label': '团伙套现',
}

async function fetchData() {
  const promises = Object.keys(scenarios).map((s) =>
    nebulaExec(`desc edge ${s}`),
  )
  const resps = await Promise.all(promises)
  resps.forEach((resp, idx) => {
    scenarioStat.value[Object.keys(scenarios)[idx]] = resp.Field.length
  })
  console.log(resps)
  labelCount.value = sum(Object.values(scenarioStat.value))
  useMetaStore().labelCount = labelCount.value

  merchantCount.value = Math.min(props.data['mcht_infom'], window.MERCHANT_COUNT)
  portraitCount.value = Math.min(sum(Object.keys(scenarios).map(s => props.data[s])), window.PORTRAIT_COUNT)

  loading.value = false
}

fetchData()
</script>

<style scoped>
:global(h2#card-usage ~ .example .example-showcase) {
  background-color: var(--el-fill-color) !important;
}

.el-statistic {
  --el-statistic-content-font-size: 28px;
}

.statistic-card {
  height: 100%;
  padding: 20px;
  border-radius: 4px;
  /* background-color: var(--el-bg-color-overlay); */
  background-image: linear-gradient(45deg, #416ce1 5%, transparent 105%);


}

.statistic-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--el-text-color-regular);
  margin-top: 16px;
}

.statistic-footer .footer-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.statistic-footer .footer-item span:last-child {
  display: inline-flex;
  align-items: center;
  margin-left: 4px;
}

.green {
  color: var(--el-color-success);
}

.red {
  color: var(--el-color-error);
}

.lcd {
  color: white;
  font-family: 'LCD', sans-serif;
}
</style>
